package dao1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
import java.sql.ResultSet;

//工具类
final class JDBCUtil {// DBUtil DBTool

	private JDBCUtil() {

	}

	static ResourceBundle rs = ResourceBundle.getBundle("studentRecord.jdbc1");
	static String driver = rs.getString("driver");
	static String url = rs.getString("url");
	static String user = rs.getString("user");
	static String pass = rs.getString("pass");
	static {
		try {
			Class.forName(driver);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() throws Exception {
		try {
			return DriverManager.getConnection(url, user, pass);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;

	}

	public static Connection getConection1() throws SQLException {
		return DriverManager.getConnection(url, user, pass);
	}

	public static void close(Connection conn, Statement st) {
		close(conn, st, null);
	}

	public static void close(Connection conn, Statement st, ResultSet rd) {
		try {
			if (rd != null) {
				rd.close();
				rd = null;
			}
			if (st != null) {
				st.close();
				st = null;
			}
			if (conn != null) {
				conn.close();
				conn = null;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
